/**
 * 份额流水
 * Created by KY on 2017/4/18.
 */

define(['ldfw/core','art', 'text!tpl/position/detail.tpl',
        'comps/ajax', 'ldfw/utils/format', 'ldfw/helper/formatHelper'],
    function (LDFW,artTemplate, tpl, ajax) {
        const rowTpl = `{{each $data record}}
                <div class="weui-form-preview">
                <div class="weui-form-preview__hd {{if record.occur_dir == 1}}increase{{else}}decrease{{/if}}">
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label"><%=$imports.getDict('busi_oper',record.busi_oper)%></label>
                        <span class="weui-form-preview__value"><%=$imports.format('number','$0.00',record.occur_share)%></span>
                    </div>
                </div>
                <div class="weui-form-preview__bd">
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">产品名称</label>
                        <span class="weui-form-preview__value">{{record.pd_name}}</span>
                    </div>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">确认时间</label>
                        <span class="weui-form-preview__value"><%=$imports.format('date','yyyy-MM-dd',record.confirm_date)%></span>
                    </div>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label"><%=$imports.getDict('busi_oper',record.busi_oper)%>金额</label>
                        <span class="weui-form-preview__value">¥<%=$imports.format('number','$0.00',record.confirm_apply)%></span>
                    </div>
                     <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label"><%=$imports.getDict('busi_oper',record.busi_oper)%>净值</label>
                        <span class="weui-form-preview__value"><%=$imports.format('number','0.0000',record.unit_nav)%></span>
                    </div>
                </div>
                <div class="weui-form-preview__ft">
                </div>
            </div>
        {{/each}}`
        var View = LDFW.Container.extend({
            tpl: tpl,
            className:'panel detail-panel',
            initialize: function () {
                this.on('shown', function () {
                    this.loadData()
                })
            },
            events:{
                'click a[name="showTimeLine"]':'showTimeLine'
            },
            setProductNo: function (pd_no) {
                this.pd_no = pd_no
            },
            loadData: function () {
                const _this = this
                let param = {
                    pd_no: this.pd_no,
                    qry_begin_date: 0,
                    qry_end_date: new Date().format('yyyyMMdd'),
                }
                //查申赎流水
                ajax.post('pfL.1.224', param).success(function (resp) {
                    if(resp.result){
                        resp.result.sort((a,b)=>{
                            return b.init_date - a.init_date
                        })
                        let html = artTemplate.compile(rowTpl)(resp.result)
                        _this.$el.find('.detail-panel_body').html(html)
                    }
                })
            },
            showTimeLine:function(event){
                LDFW.navigate('position/timeline/'+$(event.target).attr('contra-no'))
            }
        })
        return new View()
    })